package com.bicon.botu.mall.goods.controller;

import com.bicon.botu.mall.goods.commons.GoodsConstants;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.core.base.common.utils.StringUtils;
import com.bicon.botu.mall.goods.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 品牌 管理端对接接口
 *
 * @author 吕祥
 * @date 2017/7/27 16:09
 */
@RestController
@RequestMapping("/V1.0.0/brand")
public class BrandController {

    @Autowired
    IBrandService iBrandService;

    /**
     * 新增品牌
     *
     * @param chinaName   中文名称
     * @param englishName 英文名称
     * @param logo        logo图标
     * @param state       是否启用(0 = 已启用， 1 = 未启用)
     * @param remark      品牌描述
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public BaseResult add(@RequestParam String chinaName, @RequestParam String englishName,
                          @RequestParam(required = false) String logo, @RequestParam String state, @RequestParam String remark) {
        return iBrandService.add(chinaName, englishName, logo, state, remark);
    }

    /**
     * 品牌修改
     *
     * @param id          品牌id
     * @param chinaName   中文名称
     * @param englishName 英文名称
     * @param logo        logo图标
     * @param state       是否启用(0 = 已启用， 1 = 未启用)
     * @param remark      品牌描述
     * @return
     */
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public BaseResult updateById(@RequestParam String id, @RequestParam(required = false) String chinaName,
                                 @RequestParam(required = false) String englishName, @RequestParam(required = false) String logo,
                                 @RequestParam(required = false) String state, @RequestParam(required = false) String remark) {
        return iBrandService.updateById(id, chinaName, englishName, logo, state, remark);
    }

    /**
     * 删除品牌
     *
     * @param id 品牌id
     * @return
     */
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public BaseResult deleteById(@RequestParam String id) {
        return iBrandService.deleteById(id);
    }

    /**
     * 查询所有品牌
     *
     * @return 所有品牌信息
     */
    @RequestMapping(value = "/findAll", method = RequestMethod.GET)
    public BaseResult findAll() {
        return iBrandService.findAll();
    }

    /**
     * 根据品牌名称 查询品牌
     *
     * @param brandName 品牌path
     * @return
     */
    @RequestMapping(value = "findByBrandName", method = RequestMethod.POST)
    public BaseResult findByBrandName(@RequestParam String brandName) {
        if (StringUtils.isBlank(brandName)) {
            return new BaseResult(GoodsConstants.RESPONSE_CODE_200, GoodsConstants.RESPONSE_MESSAGE_200, null);
        }
        return iBrandService.findByBrandName(brandName);
    }

    /**
     * 根据品牌id查询品牌
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "findBrand", method = RequestMethod.POST)
    public BaseResult findBrand(@RequestParam String id) {
        if (StringUtils.isBlank(id)) {
            return new BaseResult(GoodsConstants.RESPONSE_CODE_400, GoodsConstants.RESPONSE_MESSAGE_400);
        }
        return new BaseResult(GoodsConstants.RESPONSE_CODE_200, GoodsConstants.RESPONSE_MESSAGE_200, iBrandService.selectById(id));
    }

    /**
     * 品牌 分页查询
     *
     * @param pageNo    页数
     * @param pageSize  页面数量
     * @return
     */
    @RequestMapping(value = "findPage", method = RequestMethod.POST)
    public BaseResult findPage(@RequestParam(defaultValue = "1") int pageNo, @RequestParam(defaultValue = "1") int pageSize) {
        if (pageNo <= 0 || pageSize <= 0) {
            return new BaseResult(GoodsConstants.RESPONSE_CODE_200, GoodsConstants.RESPONSE_MESSAGE_200);
        }
        return iBrandService.findPage(pageNo, pageSize);
    }
}
